#pragma once

#include "stdafx.h"

#include "User.h"

class PasswordManager
{
public:
    PasswordManager(LONG& res);
    ~PasswordManager();

    LONG IsFirstTime();

    BOOL IsValidPassword(TCHAR* pwd);
    LONG SavePassword(TCHAR* pwd);

protected:
    DWORD Encrypt(TCHAR* pwd, TCHAR* encrypted, int encryptLen);
    HKEY m_hKCurVer;
};

class RegistryManager
{
public:
    RegistryManager(User* user, LONG& res);
    ~RegistryManager();

    LONG SaveUser();
    LONG AddMgrStartKey();
    BOOL IsManagerStarted();
    BOOL StopManagerIfStarted();
    LONG ReadCredentials();
    LONG ReadCurrent();

protected:
    User* m_user;
    HKEY m_hKCurVer;
    HANDLE m_hToken;
    bool m_tokenOK;
    bool m_regLoaded;
};


LONG APIENTRY StartManager();
LONG APIENTRY StopManager();
BOOL APIENTRY HasToStop();

LONG APIENTRY ManagerFullPath(User* usr, TCHAR* path, int pathSize, bool withQuote);

User* APIENTRY InitUser(const TCHAR* userName);
User* APIENTRY InitUser(NET_DISPLAY_USER* user);

LONG APIENTRY ReadCredentials(User* usr);

LONG APIENTRY ReadCurrent(User* usr);
LONG APIENTRY SaveCurrent(User* usr);

int APIENTRY Day(SYSTEMTIME& st);

void APIENTRY Log(const TCHAR* str);
void APIENTRY Log(const TCHAR* str, int err);
